#include <iostream>
#include <cstdio>
using namespace std;
int main() {
    int n, m;
    cin>>n>>m;
    int res=0;
    for (int i=1; i<=n; i++) {
        res=(res+m)%i;
    }
    cout<<res+1<<endl;
    return 0;
}
